package com.jiuzhou.guanwang.jzcp.activity;

import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jiuzhou.guanwang.jzcp.R;
import com.jiuzhou.guanwang.jzcp.fragment.JclqFragment;
import com.jiuzhou.guanwang.jzcp.fragment.JczqFragment;


public class SportActivity extends AppCompatActivity implements View.OnClickListener {
    private JclqFragment mJclqFragment;
    private JczqFragment mJczqFragment;
    private RelativeLayout mLqRl;
    private TextView mLqTv;
    private View mLqV;
    private RelativeLayout mZqRl;
    private TextView mZqTv;
    private View mZqV;

    public int intiLayout() {
        return R.layout.activity_sport;
    }

    public void initView() {
        this.mZqRl = (RelativeLayout) findViewById(R.id.rl_zq);
        this.mLqRl = (RelativeLayout) findViewById(R.id.rl_lq);
        this.mZqTv = (TextView) findViewById(R.id.tv_zq);
        this.mLqTv = (TextView) findViewById(R.id.tv_lq);
        this.mZqV = findViewById(R.id.view_zq);
        this.mLqV = findViewById(R.id.view_lq);
        this.mZqRl.setOnClickListener(this);
        this.mLqRl.setOnClickListener(this);
    }

    public void initData() {
        String name = getIntent().getStringExtra("name");
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        if (this.mJczqFragment == null) {
            this.mJczqFragment = new JczqFragment();
        }
        if (this.mJclqFragment == null) {
            this.mJclqFragment = new JclqFragment();
        }
        if ("竞猜篮球".equals(name)) {
            setLqTab();
            transaction.add( R.id.view_container, this.mJclqFragment);
            transaction.commit();
            return;
        }
        setZqTab();
        transaction.add(R.id.view_container, this.mJczqFragment);
        transaction.commit();
    }

    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.rl_lq:
                setLqTab();
                if (this.mJclqFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mJczqFragment).show(this.mJclqFragment).commit();
                    return;
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mJczqFragment).add((int) R.id.view_container, this.mJclqFragment).commit();
                    return;
                }
            case R.id.rl_zq:
                setZqTab();
                if (this.mJczqFragment.isAdded()) {
                    getSupportFragmentManager().beginTransaction().hide(this.mJclqFragment).show(this.mJczqFragment).commit();
                    return;
                } else {
                    getSupportFragmentManager().beginTransaction().hide(this.mJclqFragment).add((int) R.id.view_container, this.mJczqFragment).commit();
                    return;
                }
            default:
                return;
        }
    }

    private void setLqTab() {
        this.mLqTv.setTextColor(getResources().getColor(R.color.red));
        this.mZqTv.setTextColor(getResources().getColor(R.color.common_60));
        this.mLqV.setBackgroundColor(getResources().getColor(R.color.red));
        this.mZqV.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
    }

    private void setZqTab() {
        this.mZqTv.setTextColor(getResources().getColor(R.color.red));
        this.mLqTv.setTextColor(getResources().getColor(R.color.common_60));
        this.mZqV.setBackgroundColor(getResources().getColor(R.color.red));
        this.mLqV.setBackgroundColor(getResources().getColor(R.color.circle_remark_publish_bg));
    }
}